// Magic Software, Inc.
// http://www.magic-software.com
// Copyright (c) 2000, All Rights Reserved
//
// Source code from Magic Software is supplied under the terms of a license
// agreement and may not be copied or disclosed except in accordance with the
// terms of that agreement.  The various license agreements may be found at
// the Magic Software web site.  This file is subject to the license
//
// RESTRICTED USE SOURCE CODE
// http://www.magic-software.com/License/restricted.pdf

#include "MgcRenderer.h"
#include "MgcParticles.h"

MgcImplementRTTI(MgcParticles,MgcPolypoint);
MgcImplementStream(MgcParticles);

//---------------------------------------------------------------------------
MgcParticles::MgcParticles (unsigned int uiVertexQuantity,
    MgcVector3* akVertex, MgcVector3* akNormal, MgcColor* akColor,
    bool bUseTexture, MgcReal* afSize)
    :
    MgcPolypoint(uiVertexQuantity,akVertex,akNormal,akColor,0)
{
    assert( afSize );

    m_fSizeAdjust = 1.0;
    m_afSize = afSize;
    m_bUseTexture = bUseTexture;
}
//---------------------------------------------------------------------------
MgcParticles::MgcParticles ()
{
    m_fSizeAdjust = 0.0;
    m_afSize = 0;
    m_bUseTexture = false;
}
//---------------------------------------------------------------------------
MgcParticles::~MgcParticles ()
{
    delete[] m_afSize;
}
//---------------------------------------------------------------------------
void MgcParticles::Draw (MgcRenderer& rkRenderer)
{
    // Bypass the MgcPolypoint::Draw since we want to use the particle sizes
    // and global scale in the drawing.
    MgcGeometry::Draw(rkRenderer);
    rkRenderer.Draw(*this);
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// streaming
//---------------------------------------------------------------------------
MgcObject* MgcParticles::Factory (MgcStream& rkStream)
{
    MgcParticles* pkObject = new MgcParticles;
    MgcStream::Link* pkLink = new MgcStream::Link(pkObject);
    pkObject->Load(rkStream,pkLink);
    return pkObject;
}
//---------------------------------------------------------------------------
void MgcParticles::Load (MgcStream& rkStream, MgcStream::Link* pkLink)
{
    MgcPolypoint::Load(rkStream,pkLink);

    // native data
    MgcStreamRead(rkStream,m_fSizeAdjust);
    MgcStreamRead(rkStream,m_bUseTexture);
    m_afSize = new MgcReal[m_uiVertexQuantity];
    MgcStreamRead(rkStream,m_afSize,m_uiVertexQuantity);
}
//---------------------------------------------------------------------------
void MgcParticles::Link (MgcStream& rkStream, MgcStream::Link* pkLink)
{
    MgcPolypoint::Link(rkStream,pkLink);
}
//---------------------------------------------------------------------------
bool MgcParticles::Register (MgcStream& rkStream)
{
    return MgcPolypoint::Register(rkStream);
}
//---------------------------------------------------------------------------
void MgcParticles::Save (MgcStream& rkStream)
{
    MgcPolypoint::Save(rkStream);

    // native data
    MgcStreamWrite(rkStream,m_fSizeAdjust);
    MgcStreamWrite(rkStream,m_bUseTexture);
    MgcStreamWrite(rkStream,m_afSize,m_uiVertexQuantity);
}
//---------------------------------------------------------------------------
